package com.travel.server.manager.impl.sal;

import com.travel.common.CommonConstant;
import com.travel.common.excel.ExcelData;
import com.travel.server.manager.impl.enums.OrderStepEnum;
import com.travel.server.manager.model.OrderInfo;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/6 18:05
 * @Desc:
 */
public class OrderSal {

    private static final int ALL = 1;

    private static final int WAIT_APPLY =  2;

    private static final int WAIT_EXAM = 3;

    private static final int WAIT_PROJECT = 4;

    private static final int WAIT_DATA = 5;

    private static final int PROJECT_ING = 6;

    private static final int PROJECT_END = 7;

    public static List<String> getStepList(Integer label){
        switch (label){
            case ALL : return null;
            case WAIT_APPLY : return Arrays.asList(OrderStepEnum.APPLY_WAIT.getStep());
            case WAIT_EXAM : return Arrays.asList(OrderStepEnum.QUESTION_WAIT_EXAM.getStep(), OrderStepEnum.DATA_WAIT_EXAM.getStep());
            case WAIT_PROJECT : return Arrays.asList(OrderStepEnum.PROJECT_WAIT.getStep());
            case WAIT_DATA : return Arrays.asList(OrderStepEnum.DATA_WAIT_EXAM.getStep());
            case PROJECT_ING : return Arrays.asList(OrderStepEnum.ING.getStep());
            case PROJECT_END : return Arrays.asList(OrderStepEnum.END.getStep());
        }
        return null;
    }

    public static Long getTotalAmount(OrderInfo orderInfo){
        if(orderInfo.getOrderAmount() == null){
            return null;
        }
        Long totalAmount = orderInfo.getOrderAmount();
        Integer discountAmount = orderInfo.getDiscountAmount();
        Integer freightAmount = orderInfo.getFreightAmount();
        if(discountAmount != null){
            totalAmount = totalAmount + discountAmount;
        }
        if(freightAmount != null){
            totalAmount = totalAmount + freightAmount;
        }
        return totalAmount;
    }

    /**
     * 生成新订单号
     * @return
     */
    public static String getNewOrderId(){
        return "T" + System.currentTimeMillis();
    }

    /**
     * 设置最新备注
     * @param oldNote
     * @param newNote
     * @return
     */
    public static String getNewNote(String oldNote, String newNote){
        if(StringUtils.isBlank(oldNote)){
            return newNote;
        }else if(StringUtils.isBlank(newNote)){
            return oldNote;
        }else{
            return oldNote + CommonConstant.SEMICOLON_STR + newNote;
        }
    }

    public static ExcelData makeExcelData(List<List<Object>> rows){
        List<String> title = Arrays.asList("订单编号", "项目名称", "出团编号", "出行日期", "优惠", "小计", "客户姓名", "性别", "手机", "微信", "邮箱", "收货地址", "备注");
        ExcelData excelData = new ExcelData();
        excelData.setTitles(title);
        excelData.setRows(rows);
        excelData.setName("订单报表");
        return excelData;
    }
}
